<!-- 功能：用户管理 | 作者：menghao.yan | 邮箱：yxs2615@163.com | 时间：2023年08月21日 22:47:48 -->
<template>
  <a-tabs v-model:activeKey="activeKey" type="card" class="y-tabs">
    <a-tab-pane key="yongHu" tab="用户">
      <a-card>
        <a-row align="middle">
          <a-col :span="16">
            <a-space>
              <a-button type="link" class="y-btn" @click="openXinJianYongHuModal">
                <template #icon>
                  <plus-outlined />
                </template>
                新建用户
              </a-button>
              <!-- 弹窗 - 新建用户 -->
              <xinJianYonghuModal v-model:visible="visibleXinJianYongHuModal"></xinJianYonghuModal>
              <a-button type="link" class="y-btn">
                <template #icon>
                  <delete-outlined />
                </template>
                批量删除
              </a-button>
            </a-space>
          </a-col>
          <a-col :span="8">
            <a-input v-model:value="searchValueYongHu">
              <template #addonBefore>
                <search-outlined /> 搜索:
              </template>
            </a-input>
          </a-col>
        </a-row>
        <a-table bordered :data-source="dataSourceYongHu" :columns="columnsYongHu" class="y-table" :pagination="paginationYongHu">
          <template #bodyCell="{ text, column, record }">
            <template v-if="column.key === 'userName'">
              <a-space class="y-yongHu-table-name">
                <span>{{text}}</span>
                <a-tooltip color="#2e6e9e" placement="right">
                  <template #title>编辑</template>
                  <a-button type="link" @click="">
                    <template #icon>
                      <edit-outlined />
                    </template>
                  </a-button>
                </a-tooltip>
                <a-tooltip color="#2e6e9e" placement="right">
                  <template #title>删除</template>
                  <a-button type="link" @click="">
                    <template #icon>
                      <delete-outlined />
                    </template>
                  </a-button>
                </a-tooltip>
              </a-space>
            </template>
          </template>
        </a-table>
      </a-card>
    </a-tab-pane>

    <a-tab-pane key="zu" tab="组">
      <a-card>
        <a-row align="middle">
          <a-col :span="16">
            <a-space>
              <a-button type="link" class="y-btn" @click="openXinJianZuModal">
                <template #icon>
                  <plus-outlined />
                </template>
                新建组
              </a-button>
              <!-- 弹窗 - 新建组 -->
              <xinJianZuModal v-model:visible="visibleXinJianZuModal"></xinJianZuModal>
              <a-button type="link" class="y-btn">
                <template #icon>
                  <delete-outlined />
                </template>
                批量删除
              </a-button>
            </a-space>
          </a-col>
          <a-col :span="8">
            <a-input v-model:value="searchValueZu">
              <template #addonBefore>
                <search-outlined /> 搜索:
              </template>
            </a-input>
          </a-col>
        </a-row>
        <a-table bordered :data-source="dataSourceZu" :columns="columnsZu" class="y-table" :pagination="paginationZu">
          <template #bodyCell="{ text, column, record }">
            <template v-if="column.key === 'userName'">
              <a-space class="y-zu-table-name">
                <span>{{text}}</span>
                <a-tooltip color="#2e6e9e" placement="right">
                  <template #title>编辑</template>
                  <a-button type="link" @click="">
                    <template #icon>
                      <edit-outlined />
                    </template>
                  </a-button>
                </a-tooltip>
                <a-tooltip color="#2e6e9e" placement="right">
                  <template #title>删除</template>
                  <a-button type="link" @click="">
                    <template #icon>
                      <delete-outlined />
                    </template>
                  </a-button>
                </a-tooltip>
              </a-space>
            </template>
          </template>
        </a-table>
      </a-card>
    </a-tab-pane>
  </a-tabs>
</template>

<script setup>
import xinJianYonghuModal from './modal/xinJianYongHuModal.vue'
import xinJianZuModal from './modal/xinJianZuModal.vue'

const activeKey = ref('yongHu')

// -- 用户
const visibleXinJianYongHuModal = ref(false)

const openXinJianYongHuModal = () => {
  visibleXinJianYongHuModal.value = true
}

const searchValueYongHu = ref('')

// 表格列
const columnsYongHu = ref([
  {
    title: '用户名',
    dataIndex: 'userName',
    key: 'userName',
    align: 'center',
    sorter: {
      compare: (a, b) => a.userName.localeCompare(b.userName),
      multiple: 1
    }
  },
  {
    title: '用户ID',
    dataIndex: 'userId',
    key: 'userId',
    align: 'center',
    sorter: {
      compare: (a, b) => a.userId.localeCompare(b.userId),
      multiple: 2
    }
  },
  {
    title: '真实姓名',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
    sorter: {
      compare: (a, b) => a.name.localeCompare(b.name),
      multiple: 3
    }
  }
])

// 表格数据
const dataSourceYongHu = ref([
  {
    key: '1',
    name: 'John Brown',
    userId: '1',
    userName: 'john'
  },
  {
    key: '2',
    name: 'Jim Green',
    userId: '2',
    userName: 'jim'
  }
])

// 分页
const paginationYongHu = {
  current: 1,
  pageSize: 10,
  showQuickJumper: true,
  showSizeChanger: true,
  total: 0,
  showTotal: (total, range) => {
    return `${range[0]}-${range[1]} 共 ${total} 条数据`
  },
  onChange: (page, pageSize) => {
    console.log('用户管理 > 用户分页改变>>', page, pageSize)
  }
}

// -- 组
const visibleXinJianZuModal = ref(false)

const openXinJianZuModal = () => {
  visibleXinJianZuModal.value = true
}

const searchValueZu = ref('')

// 表格列
const columnsZu = ref([
  {
    title: '组名',
    dataIndex: 'groupName',
    key: 'groupName',
    align: 'center',
    sorter: {
      compare: (a, b) => a.groupName.localeCompare(b.groupName),
      multiple: 1
    }
  },
  {
    title: '组ID',
    dataIndex: 'groupId',
    key: 'groupId',
    align: 'center',
    sorter: {
      compare: (a, b) => a.groupId.localeCompare(b.groupId),
      multiple: 2
    }
  },
  {
    title: '组成员',
    dataIndex: 'GroupUsers',
    key: 'GroupUsers',
    align: 'center',
    sorter: {
      compare: (a, b) => a.GroupUsers.localeCompare(b.GroupUsers),
      multiple: 3
    }
  }
])

// 表格数据
const dataSourceZu = ref([
  {
    key: '1',
    groupName: '组1',
    groupId: '1',
    GroupUsers: '1,2,3,4,5,6,7,8,9,10'
  },
  {
    key: '2',
    groupName: '组2',
    groupId: '2',
    GroupUsers: '1,2,3,4,5,6,7,8,9,10'
  },
  {
    key: '3',
    groupName: '组3',
    groupId: '3',
    GroupUsers: '1,2,3,4,5,6,7,8,9,10'
  }
])

// 分页
const paginationZu = {
  current: 1,
  pageSize: 10,
  showQuickJumper: true,
  showSizeChanger: true,
  total: 0,
  showTotal: (total, range) => {
    return `${range[0]}-${range[1]} 共 ${total} 条数据`
  },
  onChange: (page, pageSize) => {
    console.log('用户管理 > 组分页改变>>', page, pageSize)
  }
}
</script>

<style scoped lang='scss'>
.ant-row {
  margin-bottom: 10px;
}

.y-yongHu-table-name,
.y-zu-table-name {
  color: #67c23a;
}
</style>